Corda 交易有其特有的流程限制,收集所有參與者的簽章,則達成交易共識寫入賬本。
交易依據狀態分為 2 種:
fun toWireTransaction(): WireTransaction
verifySignatures()
兩者差異為是否成功完成以下函式。
fun toSignedTransaction(checkSufficientSignatures: Boolean = true): SignedTransaction
checkSufficientSignatures
verifySignatures()
用以建立交易的實體物件,將所需物件參數傳入後,回傳交易物件以供傳送執行。
完整交易包含了幾個物件:
物件定義:
val type: TransactionType = TransactionType.General()
val inputs: MutableList<StateRef>
val outputs: MutableList<TransactionState<ContractState>>
val commands: MutableList<Command>
val signers: MutableSet<CompositeKey>
var timestamp:Timestamp?
val attachments:MutableList<SecureHash>
val currentSigs:MutableList<DigitalSignature.WithKey>
var notary: Party?
TransactionBuilder 提供的函式,用以取得物件、設定時間戳記、設定簽章:
fun withItems(var arg items: Any): TransactionBuilder
fun setTime(newTimestamp: Timestamp)
fun signWith(key: KeyPair): TransactionBuilder
程式碼範例:
val txBuilder = TransactionType.General.Builder(notary = null)
val notaryRef = serviceHub.networkMapCache.notaryNodes.single().notaryIdentity
val state = TransactionState(Cash.State(amount, owner), notaryRef))
val command = Command(Cash.Commands.Issue(), state.participants)
val unsignedTx = txBuilder.withItems(state, command)